package com.android.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SwitchCompat;

import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.android.R;
import com.android.SQL.MySQLiteOpenHelper;
import com.android.bean.DeliveryAdr;

public class DetailDeliveryActivity extends AppCompatActivity  {

    MySQLiteOpenHelper myDbHelper;
    SQLiteDatabase db;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_delivery_detail);

        myDbHelper = new MySQLiteOpenHelper(DetailDeliveryActivity.this);
        db = myDbHelper.getReadableDatabase();

        Toast.makeText(this, "创建数据库", Toast.LENGTH_SHORT).show();


        EditText evtel = findViewById(R.id.et_delivery_phone);
        EditText evname = findViewById(R.id.et_delivery_receiver);
        EditText evloc = findViewById(R.id.et_delivery_location);
        SwitchCompat scdef = findViewById(R.id.sc_delivery_default);
        Button btsave = findViewById(R.id.btn_save);

        btsave.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                ContentValues values = new ContentValues();
                values.put(DeliveryAdr.DeliveryEntry.COLUMN_PEOPLE_NAME ,
                        evname.getText().toString());
                values.put(DeliveryAdr.DeliveryEntry.COLUMN_PEOPLE_TELE,
                        evtel.getText().toString());
                values.put(DeliveryAdr.DeliveryEntry.COLUMN_DETAIL_ADR ,
                        evloc.getText().toString());
                if(scdef.isChecked())
                    values.put(DeliveryAdr.DeliveryEntry.COLUMN_IS_RAW ,
                            "true");
                else
                    values.put(DeliveryAdr.DeliveryEntry.COLUMN_IS_RAW ,
                            "false");
                long r = db.insert(
                        DeliveryAdr.DeliveryEntry.TABLE_NAME,
                        null,
                        values);
                db.close();
                Log.e("TAG", "保存数据");
            }
        });
    }
}